<?php
require_once dirname(dirname(__FILE__)) . '/shared/config/config.php';
require_once DOCUMENT_ROOT . DIR_INCLUDE . 'html_generator.php';
require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_bet_calculators.php';
require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_security.php';
lib_session::start_session();

$username_main = $_SESSION['user_info']['username'];
$user_main = api_security::get_user_by_username($username_main);
$match_id = filter_input(INPUT_POST, "hidd_match_id");
$roulette_id = filter_input(INPUT_POST, "hidd_roulette_id");
$game_id = filter_input(INPUT_POST, "ddl_game");
if (!empty($game_id)) {
    $match_id = api_roulette::get_sub_match_id_by_game_id_and_parent_id($game_id, $roulette_id);
}


$affiliate_email = filter_input(INPUT_POST, "txt_affiliate_email");
$choice_id = filter_input(INPUT_POST, "ddl_choice");
$bet_amount = filter_input(INPUT_POST, "txt_amount");
if (empty($bet_amount)) {
    $bet_amount = 100; // default
}

$bet_history = [
    'match_id' => $match_id,
    'affiliate_email' => $affiliate_email,
    'choice_id' => $choice_id,
    'bet_amount' => $bet_amount,
    'user_id' => $user_main['id'],
];

$profit_if_win = api_bet_calculators::calculate_profit_if_bet_win($bet_history, TRUE);

$result = show_profit_text($profit_if_win, $bet_amount, $match_id, TRUE);
//var_dump($result) ;
//        exit();
echo $result['profit_if_win_text'];